﻿#define DEBUGCHRACTER
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using SpiritAlight.Input;
using SpiritAlight.GeneralClac;
using SpiritAlight.Character.Unit;
using SpiritAlight.Stage;
using SpiritAlight.Character.Unit.EntitySpirit;
using SpiritAlight.SceneManagement;
using SpiritAlight.Scene;
using SpiritAlight.Animation;


#if DEBUGCHRACTER
namespace SpiritAlight.Character
{
    public class Player : Army
    {   
        /// <summary>
        /// プレイヤーテクスチャー
        /// </summary>
        AnimationSprite texture = new AnimationSprite();

        List<ASpirit> spiritList;

        /// <summary>
        /// 詠唱時間
        /// </summary>
        public int CastTime
        {
            get { return castTime; }
        }
        int castTime = 0;
        



        protected override UnitStatus Status
        {
            get { return status; }
            set { status = value; }
        }
        UnitStatus status = new UnitStatus();


        public Player(List<ASpirit> spirit)
        {
            spiritList = spirit;
        }
        /// <summary>
        /// キャラクターの初期化
        /// </summary>
        public override void Initialize()
        {
            IsSelect = false;
            //ユニットステータス初期化
            Status.Size = new Vector2(80.0f, 120.0f);
            Status.AttackInterval = 100;
            Status.HitPoint = 50;
            Status.Power = 1;
            Status.RangeAttackOperation = 100.0f;
            Status.RangeSearchOperation = 300.0f;

            texture.FrameRate = 15;
            texture.Mode = AnimationMode.Repeat;
        }
        SpriteFont font;
        
        int[,] aFlag = new int[4, 3];
    


        /// <summary>
        /// リソース読み込み。
        /// </summary>
        /// <param name="Content">コンテンツマネージャ</param>
        public override void LoadContent()
        {
            {
                font = SceneManager.Content.Load<SpriteFont>("DefaultFont");
                const string pathW = "Character/Army/Player/Walk/";
                aFlag[(int)Direction.Up,    (int)CharacterState.Wait] = texture.LoadNewPattern(pathW + "back_01", pathW + "back_02", pathW + "back_01", pathW + "back_03");
                aFlag[(int)Direction.Down,  (int)CharacterState.Wait] = texture.LoadNewPattern(pathW + "front_01", pathW + "front_02", pathW + "front_01", pathW + "front_03");
                aFlag[(int)Direction.Left,  (int)CharacterState.Wait] = texture.LoadNewPattern(pathW + "left_01", pathW + "left_02");
                aFlag[(int)Direction.Right, (int)CharacterState.Wait] = texture.LoadNewPattern(pathW + "right_01", pathW + "right_02");
            }
            {
                const string pathD = "Character/Army/Player/Damage/";

                aFlag[(int)Direction.Up, (int)CharacterState.Damage] = texture.LoadNewPattern(
                    pathD + "back_01",
                    pathD + "back_02",
                    pathD + "back_03",
                    pathD + "back_04",
                    pathD + "back_05");

                aFlag[(int)Direction.Down, (int)CharacterState.Damage] = texture.LoadNewPattern(
                    pathD + "front_01",
                    pathD + "front_02",
                    pathD + "front_03",
                    pathD + "front_04",
                    pathD + "front_05");

                aFlag[(int)Direction.Left, (int)CharacterState.Damage] = texture.LoadNewPattern(
                    pathD + "left_01",
                    pathD + "left_02",
                    pathD + "left_03",
                    pathD + "left_04",
                    pathD + "left_05");

                aFlag[(int)Direction.Right, (int)CharacterState.Damage] = texture.LoadNewPattern(
                    pathD + "right_01",
                    pathD + "right_02",
                    pathD + "right_03",
                    pathD + "right_04",
                    pathD + "right_05");
            }
            {
                const string pathS = "Character/Army/Player/Summon/";

                aFlag[(int)Direction.Up, (int)CharacterState.Attack] = texture.LoadNewPattern(
                    pathS + "back_01",
                    pathS + "back_02",
                    pathS + "back_03",
                    pathS + "back_04",
                    pathS + "back_05",
                    pathS + "back_06",
                    pathS + "back_07");

                aFlag[(int)Direction.Down, (int)CharacterState.Attack] = texture.LoadNewPattern(
                    pathS + "front_01",
                    pathS + "front_02",
                    pathS + "front_03",
                    pathS + "front_04",
                    pathS + "front_05",
                    pathS + "front_06",
                    pathS + "front_07");

                aFlag[(int)Direction.Left, (int)CharacterState.Attack] = texture.LoadNewPattern(
                    pathS + "left_01",
                    pathS + "left_02",
                    pathS + "left_03",
                    pathS + "left_04",
                    pathS + "left_05",
                    pathS + "left_06",
                    pathS + "left_07");

                aFlag[(int)Direction.Right, (int)CharacterState.Attack] = texture.LoadNewPattern(
                    pathS + "right_01",
                    pathS + "right_02",
                    pathS + "right_03",
                    pathS + "right_04",
                    pathS + "right_05",
                    pathS + "right_06",
                    pathS + "right_07");
            }
            //texture[0, 0] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/back");
            //texture[0, 1] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/back_damage");
            //texture[0, 2] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/back_magic");
            //texture[1, 0] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/front");
            //texture[1, 1] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/front_damage");
            //texture[1, 2] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/front_magic");
            //texture[2, 0] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/left");
            //texture[2, 1] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/left_damage");
            //texture[2, 2] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/left_magic");
            //texture[3, 0] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/right");
            //texture[3, 1] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/right_damage");
            //texture[3, 2] = SceneManager.Content.Load<Texture2D>("Character/Army/Player/right_magic");

            base.LoadContent();
        }

        /// <summary>
        /// プレイヤーの更新処理。
        /// </summary>
        /// <param name="inputState">現在の入力デバイスの状態。</param>
        public override void Update()
        {
            base.Update();

            if (InputState.IsDown(Keys.Z))
            {
                castTime++;
            }
            else
            {
                if (castTime > 0)
                    castTime--;
            }
            if (castTime == 60)
            {
                spiritList.Add(new Spirit1(Coordinate.ScreenToGlobal(InputState.MousePosition)));
                castTime = 0;
            }


        }

        /// <summary>
        /// キャラクターの描画処理。
        /// </summary>
        /// <param name="spriteBatch">描画するSpriteBatch</param>
        /// <param name="sceneColor">シーンの色。</param>
        public override void Draw()
        {
            GameMain.DrawObject(texture[aFlag[(int)this.Direction,(int)this.State]], Position - Camera.Position);
            SceneManager.SpriteBatch.DrawString(font, castTime.ToString(), Vector2.Zero, Color.White);
        }


    }
       
}
#endif